<template>
  <a-card :bordered="false">
    <a-col :span='5'>
      <dept-tree @select='deptSelect'></dept-tree>
    </a-col>
    <a-col :offset='1' :span='18'>
      <super-query :fieldList="tableObj.columns" @ok="handleSuperQuery"/>
      <v-table
        ref="table"
        :data="loadData"
        :columns="tableObj.columns"
      >
        <template v-slot:buttons>
          <a-button @click="$refs.userAddOrUpdate.init('','add')" icon="plus" type="primary" v-action="'sys:user:save'">新建</a-button>
        </template>
        <span slot="avatar" slot-scope="{ row,text }">
        <a-avatar size="large" :src="text" v-if="text"/>
        <a-avatar size="large" icon="user" v-else/>
      </span>
        <span slot="status" slot-scope="{ row,text }">
        <a-tag color="#108ee9">{{ text | dictFilter(statusTypeList) }}</a-tag>
      </span>
        <span slot="action" slot-scope="{ row,text }">
        <span v-action="'sys:user:update'">
          <a href="javascript:;" @click="edit(row)">编辑</a>
          <a-divider type="vertical" />
        </span>
      </span>
      </v-table>
    </a-col>
    <user-add-or-update
      @ok="queryPage"
      ref="userAddOrUpdate"
    />
  </a-card>
</template>

<script>
import { delObj, PageList } from '@api/sys/user'
import UserAddOrUpdate from './userAddOrUpdate'
import { TableMixin } from '@/mixins/TableMixin'
import { statusTypeList } from '@/dict'
import SuperQuery from '@comp/SuperQuery/SuperQuery'
import { tableObj } from './template'
import deptTree from '@/views/modules/sys/dept/deptTree'
export default {
  name: 'User',
  mixins: [TableMixin],
  components: {
    SuperQuery,
    UserAddOrUpdate,
    deptTree
  },
  data () {
    return {
      tableObj,
      statusTypeList,
      dataSource: [],
      loadData: parameter => {
        return PageList(
          Object.assign(parameter, this.queryParam,{deptId: this.deptId})
        ).then(res => {
          return res.data
        })
      },
      deptId: ''
    }
  },
  methods: {
    edit (record) {
      this.$refs.userAddOrUpdate.init(record.id, 'edit')
    },
    handleSuperQuery (params) {
      console.log(params,'params')
      if(params){
        this.queryParam.queryType = params.queryType
        this.queryParam.queryItems = encodeURI(JSON.stringify(params.queryItems))
      }else{
        this.queryParam.queryType = ''
        this.queryParam.queryItems = ''
      }
      this.queryPage()
    },
    deleteItem (record) {
      delObj(record.id).then(res => {
        this.$message.info('删除成功')
        this.queryPage()
      })
    },
    deptSelect(select){
      console.log(select,'select')
      if(!select || select.length === 0){
        this.deptId = ''
      }else if(select[0] === '0' ) {
        this.deptId = ''
      }else{
        this.deptId = select[0]
      }
      this.queryPage()
    },
    show (record) {
      this.$refs.userAddOrUpdate.init(record.id, 'show')
    }
  }
}
</script>

<style scoped>

</style>
